#pragma once

template<typename DATA_TYPE>
class LostVector
{
private:
	static const int DEFAULT_ALLOCATION_SIZE = 16;
private:
	DATA_TYPE* data;
	int allocatedSize, size;
public:
	LostVector():data(0), size(0){}
	LostVector(int a_size, DATA_TYPE value)
	{
		allocateToSize(a_size);
		for(int i=0;i<a_size;++i)
			data[i] = value;
	}
	~LostVector()
	{
		if(data)
			delete[]data;
		data = 0;
	}
public:
	void clear()
	{
		if(size != 0)
		{
			size = 0;
			if(data && data != (DATA_TYPE*)0xfefefefe)
				delete[]data;
			data = 0;
			allocateToSize(DEFAULT_ALLOCATION_SIZE);
		}
	}
public:
	void allocateToSize(int newSize)
	{
		DATA_TYPE * newList = new DATA_TYPE[newSize];
		DATA_TYPE * oldList = data;
		data = newList;
		if(oldList)
		{
			int smallerSize = allocatedSize;
			if(newSize < allocatedSize)
				smallerSize = newSize;
			for(int i=0;i<smallerSize;++i)
				set(i, oldList[i]);
		}
		delete[]oldList;
		allocatedSize = newSize;
	}
public:
	void set(int index, DATA_TYPE value)
	{
		data[index] = value;
	}
	void add(DATA_TYPE value)
	{
		if(size < 0)
			clear();
		if(data == 0)
			allocateToSize(DEFAULT_ALLOCATION_SIZE);
		if(size >= allocatedSize)
		{
			allocateToSize(allocatedSize*2);
		}
		set(size, value);
		size++;
	}
public:
	DATA_TYPE get(int index)
	{
		return data[index];
	}
	DATA_TYPE* getP(int index)
	{
		return &data[index];
	}
	int Size()
	{
		return size;
	}
public:
	DATA_TYPE remove(int index)
	{
		DATA_TYPE grabbed = data[index];
		for(int i=index;i<size;++i)
			set(i, get(i+1));
		size--;
		return grabbed;
	}
	void insert(int index, DATA_TYPE value)
	{
		for(int i=size;i>index;--i)
			set(i, get(i-1));
		data[index] = value;
		size++;
	}
};